﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Pharmacy.Entities;
using Pharmacy.Data;

#endregion

namespace Pharmacy.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="StockWarningProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class StockWarningProviderBaseCore : EntityViewProviderBase<StockWarning>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;StockWarning&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;StockWarning&gt;"/></returns>
		protected static VList&lt;StockWarning&gt; Fill(DataSet dataSet, VList<StockWarning> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<StockWarning>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;StockWarning&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<StockWarning>"/></returns>
		protected static VList&lt;StockWarning&gt; Fill(DataTable dataTable, VList<StockWarning> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					StockWarning c = new StockWarning();
					c.DrugId = (Convert.IsDBNull(row["DrugId"]))?string.Empty:(System.String)row["DrugId"];
					c.DrugName = (Convert.IsDBNull(row["DrugName"]))?string.Empty:(System.String)row["DrugName"];
					c.MinStock = (Convert.IsDBNull(row["MinStock"]))?(int)0:(System.Int32?)row["MinStock"];
					c.MaxStock = (Convert.IsDBNull(row["MaxStock"]))?(int)0:(System.Int32?)row["MaxStock"];
					c.NearestExp = (Convert.IsDBNull(row["NearestExp"]))?(int)0:(System.Int32?)row["NearestExp"];
					c.InStock = (Convert.IsDBNull(row["InStock"]))?(int)0:(System.Int32?)row["InStock"];
					c.GenericName = (Convert.IsDBNull(row["GenericName"]))?string.Empty:(System.String)row["GenericName"];
					c.Specification = (Convert.IsDBNull(row["Specification"]))?string.Empty:(System.String)row["Specification"];
					c.Unit = (Convert.IsDBNull(row["Unit"]))?string.Empty:(System.String)row["Unit"];
					c.MarkUpType = (Convert.IsDBNull(row["MarkUpType"]))?(int)0:(System.Int32?)row["MarkUpType"];
					c.CostPrice = (Convert.IsDBNull(row["CostPrice"]))?0.0m:(System.Decimal)row["CostPrice"];
					c.SellPrice = (Convert.IsDBNull(row["SellPrice"]))?0.0m:(System.Decimal)row["SellPrice"];
					c.UseGuide = (Convert.IsDBNull(row["UseGuide"]))?string.Empty:(System.String)row["UseGuide"];
					c.Precaution = (Convert.IsDBNull(row["Precaution"]))?string.Empty:(System.String)row["Precaution"];
					c.Package = (Convert.IsDBNull(row["Package"]))?string.Empty:(System.String)row["Package"];
					c.ClassificationName = (Convert.IsDBNull(row["ClassificationName"]))?string.Empty:(System.String)row["ClassificationName"];
					c.Shelf = (Convert.IsDBNull(row["Shelf"]))?string.Empty:(System.String)row["Shelf"];
					c.GroupName = (Convert.IsDBNull(row["GroupName"]))?string.Empty:(System.String)row["GroupName"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;StockWarning&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;StockWarning&gt;"/></returns>
		protected VList<StockWarning> Fill(IDataReader reader, VList<StockWarning> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					StockWarning entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<StockWarning>("StockWarning",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new StockWarning();
					}
					
					entity.SuppressEntityEvents = true;

					entity.DrugId = (System.String)reader[((int)StockWarningColumn.DrugId)];
					//entity.DrugId = (Convert.IsDBNull(reader["DrugId"]))?string.Empty:(System.String)reader["DrugId"];
					entity.DrugName = (System.String)reader[((int)StockWarningColumn.DrugName)];
					//entity.DrugName = (Convert.IsDBNull(reader["DrugName"]))?string.Empty:(System.String)reader["DrugName"];
					entity.MinStock = (reader.IsDBNull(((int)StockWarningColumn.MinStock)))?null:(System.Int32?)reader[((int)StockWarningColumn.MinStock)];
					//entity.MinStock = (Convert.IsDBNull(reader["MinStock"]))?(int)0:(System.Int32?)reader["MinStock"];
					entity.MaxStock = (reader.IsDBNull(((int)StockWarningColumn.MaxStock)))?null:(System.Int32?)reader[((int)StockWarningColumn.MaxStock)];
					//entity.MaxStock = (Convert.IsDBNull(reader["MaxStock"]))?(int)0:(System.Int32?)reader["MaxStock"];
					entity.NearestExp = (reader.IsDBNull(((int)StockWarningColumn.NearestExp)))?null:(System.Int32?)reader[((int)StockWarningColumn.NearestExp)];
					//entity.NearestExp = (Convert.IsDBNull(reader["NearestExp"]))?(int)0:(System.Int32?)reader["NearestExp"];
					entity.InStock = (reader.IsDBNull(((int)StockWarningColumn.InStock)))?null:(System.Int32?)reader[((int)StockWarningColumn.InStock)];
					//entity.InStock = (Convert.IsDBNull(reader["InStock"]))?(int)0:(System.Int32?)reader["InStock"];
					entity.GenericName = (reader.IsDBNull(((int)StockWarningColumn.GenericName)))?null:(System.String)reader[((int)StockWarningColumn.GenericName)];
					//entity.GenericName = (Convert.IsDBNull(reader["GenericName"]))?string.Empty:(System.String)reader["GenericName"];
					entity.Specification = (reader.IsDBNull(((int)StockWarningColumn.Specification)))?null:(System.String)reader[((int)StockWarningColumn.Specification)];
					//entity.Specification = (Convert.IsDBNull(reader["Specification"]))?string.Empty:(System.String)reader["Specification"];
					entity.Unit = (System.String)reader[((int)StockWarningColumn.Unit)];
					//entity.Unit = (Convert.IsDBNull(reader["Unit"]))?string.Empty:(System.String)reader["Unit"];
					entity.MarkUpType = (reader.IsDBNull(((int)StockWarningColumn.MarkUpType)))?null:(System.Int32?)reader[((int)StockWarningColumn.MarkUpType)];
					//entity.MarkUpType = (Convert.IsDBNull(reader["MarkUpType"]))?(int)0:(System.Int32?)reader["MarkUpType"];
					entity.CostPrice = (System.Decimal)reader[((int)StockWarningColumn.CostPrice)];
					//entity.CostPrice = (Convert.IsDBNull(reader["CostPrice"]))?0.0m:(System.Decimal)reader["CostPrice"];
					entity.SellPrice = (System.Decimal)reader[((int)StockWarningColumn.SellPrice)];
					//entity.SellPrice = (Convert.IsDBNull(reader["SellPrice"]))?0.0m:(System.Decimal)reader["SellPrice"];
					entity.UseGuide = (reader.IsDBNull(((int)StockWarningColumn.UseGuide)))?null:(System.String)reader[((int)StockWarningColumn.UseGuide)];
					//entity.UseGuide = (Convert.IsDBNull(reader["UseGuide"]))?string.Empty:(System.String)reader["UseGuide"];
					entity.Precaution = (reader.IsDBNull(((int)StockWarningColumn.Precaution)))?null:(System.String)reader[((int)StockWarningColumn.Precaution)];
					//entity.Precaution = (Convert.IsDBNull(reader["Precaution"]))?string.Empty:(System.String)reader["Precaution"];
					entity.Package = (reader.IsDBNull(((int)StockWarningColumn.Package)))?null:(System.String)reader[((int)StockWarningColumn.Package)];
					//entity.Package = (Convert.IsDBNull(reader["Package"]))?string.Empty:(System.String)reader["Package"];
					entity.ClassificationName = (reader.IsDBNull(((int)StockWarningColumn.ClassificationName)))?null:(System.String)reader[((int)StockWarningColumn.ClassificationName)];
					//entity.ClassificationName = (Convert.IsDBNull(reader["ClassificationName"]))?string.Empty:(System.String)reader["ClassificationName"];
					entity.Shelf = (reader.IsDBNull(((int)StockWarningColumn.Shelf)))?null:(System.String)reader[((int)StockWarningColumn.Shelf)];
					//entity.Shelf = (Convert.IsDBNull(reader["Shelf"]))?string.Empty:(System.String)reader["Shelf"];
					entity.GroupName = (reader.IsDBNull(((int)StockWarningColumn.GroupName)))?null:(System.String)reader[((int)StockWarningColumn.GroupName)];
					//entity.GroupName = (Convert.IsDBNull(reader["GroupName"]))?string.Empty:(System.String)reader["GroupName"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="StockWarning"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="StockWarning"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, StockWarning entity)
		{
			reader.Read();
			entity.DrugId = (System.String)reader[((int)StockWarningColumn.DrugId)];
			//entity.DrugId = (Convert.IsDBNull(reader["DrugId"]))?string.Empty:(System.String)reader["DrugId"];
			entity.DrugName = (System.String)reader[((int)StockWarningColumn.DrugName)];
			//entity.DrugName = (Convert.IsDBNull(reader["DrugName"]))?string.Empty:(System.String)reader["DrugName"];
			entity.MinStock = (reader.IsDBNull(((int)StockWarningColumn.MinStock)))?null:(System.Int32?)reader[((int)StockWarningColumn.MinStock)];
			//entity.MinStock = (Convert.IsDBNull(reader["MinStock"]))?(int)0:(System.Int32?)reader["MinStock"];
			entity.MaxStock = (reader.IsDBNull(((int)StockWarningColumn.MaxStock)))?null:(System.Int32?)reader[((int)StockWarningColumn.MaxStock)];
			//entity.MaxStock = (Convert.IsDBNull(reader["MaxStock"]))?(int)0:(System.Int32?)reader["MaxStock"];
			entity.NearestExp = (reader.IsDBNull(((int)StockWarningColumn.NearestExp)))?null:(System.Int32?)reader[((int)StockWarningColumn.NearestExp)];
			//entity.NearestExp = (Convert.IsDBNull(reader["NearestExp"]))?(int)0:(System.Int32?)reader["NearestExp"];
			entity.InStock = (reader.IsDBNull(((int)StockWarningColumn.InStock)))?null:(System.Int32?)reader[((int)StockWarningColumn.InStock)];
			//entity.InStock = (Convert.IsDBNull(reader["InStock"]))?(int)0:(System.Int32?)reader["InStock"];
			entity.GenericName = (reader.IsDBNull(((int)StockWarningColumn.GenericName)))?null:(System.String)reader[((int)StockWarningColumn.GenericName)];
			//entity.GenericName = (Convert.IsDBNull(reader["GenericName"]))?string.Empty:(System.String)reader["GenericName"];
			entity.Specification = (reader.IsDBNull(((int)StockWarningColumn.Specification)))?null:(System.String)reader[((int)StockWarningColumn.Specification)];
			//entity.Specification = (Convert.IsDBNull(reader["Specification"]))?string.Empty:(System.String)reader["Specification"];
			entity.Unit = (System.String)reader[((int)StockWarningColumn.Unit)];
			//entity.Unit = (Convert.IsDBNull(reader["Unit"]))?string.Empty:(System.String)reader["Unit"];
			entity.MarkUpType = (reader.IsDBNull(((int)StockWarningColumn.MarkUpType)))?null:(System.Int32?)reader[((int)StockWarningColumn.MarkUpType)];
			//entity.MarkUpType = (Convert.IsDBNull(reader["MarkUpType"]))?(int)0:(System.Int32?)reader["MarkUpType"];
			entity.CostPrice = (System.Decimal)reader[((int)StockWarningColumn.CostPrice)];
			//entity.CostPrice = (Convert.IsDBNull(reader["CostPrice"]))?0.0m:(System.Decimal)reader["CostPrice"];
			entity.SellPrice = (System.Decimal)reader[((int)StockWarningColumn.SellPrice)];
			//entity.SellPrice = (Convert.IsDBNull(reader["SellPrice"]))?0.0m:(System.Decimal)reader["SellPrice"];
			entity.UseGuide = (reader.IsDBNull(((int)StockWarningColumn.UseGuide)))?null:(System.String)reader[((int)StockWarningColumn.UseGuide)];
			//entity.UseGuide = (Convert.IsDBNull(reader["UseGuide"]))?string.Empty:(System.String)reader["UseGuide"];
			entity.Precaution = (reader.IsDBNull(((int)StockWarningColumn.Precaution)))?null:(System.String)reader[((int)StockWarningColumn.Precaution)];
			//entity.Precaution = (Convert.IsDBNull(reader["Precaution"]))?string.Empty:(System.String)reader["Precaution"];
			entity.Package = (reader.IsDBNull(((int)StockWarningColumn.Package)))?null:(System.String)reader[((int)StockWarningColumn.Package)];
			//entity.Package = (Convert.IsDBNull(reader["Package"]))?string.Empty:(System.String)reader["Package"];
			entity.ClassificationName = (reader.IsDBNull(((int)StockWarningColumn.ClassificationName)))?null:(System.String)reader[((int)StockWarningColumn.ClassificationName)];
			//entity.ClassificationName = (Convert.IsDBNull(reader["ClassificationName"]))?string.Empty:(System.String)reader["ClassificationName"];
			entity.Shelf = (reader.IsDBNull(((int)StockWarningColumn.Shelf)))?null:(System.String)reader[((int)StockWarningColumn.Shelf)];
			//entity.Shelf = (Convert.IsDBNull(reader["Shelf"]))?string.Empty:(System.String)reader["Shelf"];
			entity.GroupName = (reader.IsDBNull(((int)StockWarningColumn.GroupName)))?null:(System.String)reader[((int)StockWarningColumn.GroupName)];
			//entity.GroupName = (Convert.IsDBNull(reader["GroupName"]))?string.Empty:(System.String)reader["GroupName"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="StockWarning"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="StockWarning"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, StockWarning entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.DrugId = (Convert.IsDBNull(dataRow["DrugId"]))?string.Empty:(System.String)dataRow["DrugId"];
			entity.DrugName = (Convert.IsDBNull(dataRow["DrugName"]))?string.Empty:(System.String)dataRow["DrugName"];
			entity.MinStock = (Convert.IsDBNull(dataRow["MinStock"]))?(int)0:(System.Int32?)dataRow["MinStock"];
			entity.MaxStock = (Convert.IsDBNull(dataRow["MaxStock"]))?(int)0:(System.Int32?)dataRow["MaxStock"];
			entity.NearestExp = (Convert.IsDBNull(dataRow["NearestExp"]))?(int)0:(System.Int32?)dataRow["NearestExp"];
			entity.InStock = (Convert.IsDBNull(dataRow["InStock"]))?(int)0:(System.Int32?)dataRow["InStock"];
			entity.GenericName = (Convert.IsDBNull(dataRow["GenericName"]))?string.Empty:(System.String)dataRow["GenericName"];
			entity.Specification = (Convert.IsDBNull(dataRow["Specification"]))?string.Empty:(System.String)dataRow["Specification"];
			entity.Unit = (Convert.IsDBNull(dataRow["Unit"]))?string.Empty:(System.String)dataRow["Unit"];
			entity.MarkUpType = (Convert.IsDBNull(dataRow["MarkUpType"]))?(int)0:(System.Int32?)dataRow["MarkUpType"];
			entity.CostPrice = (Convert.IsDBNull(dataRow["CostPrice"]))?0.0m:(System.Decimal)dataRow["CostPrice"];
			entity.SellPrice = (Convert.IsDBNull(dataRow["SellPrice"]))?0.0m:(System.Decimal)dataRow["SellPrice"];
			entity.UseGuide = (Convert.IsDBNull(dataRow["UseGuide"]))?string.Empty:(System.String)dataRow["UseGuide"];
			entity.Precaution = (Convert.IsDBNull(dataRow["Precaution"]))?string.Empty:(System.String)dataRow["Precaution"];
			entity.Package = (Convert.IsDBNull(dataRow["Package"]))?string.Empty:(System.String)dataRow["Package"];
			entity.ClassificationName = (Convert.IsDBNull(dataRow["ClassificationName"]))?string.Empty:(System.String)dataRow["ClassificationName"];
			entity.Shelf = (Convert.IsDBNull(dataRow["Shelf"]))?string.Empty:(System.String)dataRow["Shelf"];
			entity.GroupName = (Convert.IsDBNull(dataRow["GroupName"]))?string.Empty:(System.String)dataRow["GroupName"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region StockWarningFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="StockWarning"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class StockWarningFilterBuilder : SqlFilterBuilder<StockWarningColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the StockWarningFilterBuilder class.
		/// </summary>
		public StockWarningFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the StockWarningFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public StockWarningFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the StockWarningFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public StockWarningFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion StockWarningFilterBuilder

	#region StockWarningParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="StockWarning"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class StockWarningParameterBuilder : ParameterizedSqlFilterBuilder<StockWarningColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the StockWarningParameterBuilder class.
		/// </summary>
		public StockWarningParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the StockWarningParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public StockWarningParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the StockWarningParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public StockWarningParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion StockWarningParameterBuilder
	
	#region StockWarningSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="StockWarning"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class StockWarningSortBuilder : SqlSortBuilder<StockWarningColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the StockWarningSqlSortBuilder class.
		/// </summary>
		public StockWarningSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion StockWarningSortBuilder

} // end namespace
